package com.syni.mdd.yhd.common.all.utils.aurora;

import cn.jiguang.common.ServiceHelper;
import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jmessage.api.JMessageClient;
import cn.jmessage.api.common.model.RegisterInfo;
import cn.jmessage.api.common.model.UserPayload;
import cn.jmessage.api.common.model.cross.CrossGroup;
import cn.jmessage.api.common.model.message.MessageBody;
import cn.jmessage.api.common.model.message.MessagePayload;
import cn.jmessage.api.group.CreateGroupResult;
import cn.jmessage.api.message.MessageType;
import cn.jmessage.api.message.SendMessageResult;
import cn.jmessage.api.resource.ResourceClient;
import cn.jmessage.api.resource.UploadResult;
import cn.jmessage.api.user.UserStateListResult;
import cn.jpush.api.push.model.Message;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.AndroidNotification;
import cn.jpush.api.push.model.notification.IosNotification;
import cn.jpush.api.push.model.notification.Notification;
import com.alibaba.fastjson.JSON;
import com.syni.mdd.yhd.common.all.config.AuroraConfig;
import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.constants.ResultCode;
import com.syni.mdd.yhd.common.all.entity.BmsBusiness;
import com.syni.mdd.yhd.common.all.entity.groupChat.BmsDxGroupChat;
import com.syni.mdd.yhd.common.all.entity.groupChat.BmsUserChat;
import com.syni.mdd.yhd.common.all.entity.user.BmsUser;
import com.syni.mdd.yhd.common.all.service.BmsUserService;
import com.syni.mdd.sjb.common.component.utils.common.utils.AppConfig;
import lombok.extern.log4j.Log4j2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @className 极光推送工具类
 * @description TOO
 * @Author cfx
 * @DATE 2019/7/16 10:40
 * @VERSION 1.0
 **/
@Log4j2
public class AuroraMessageUtils {
    public static final Logger LOG = LoggerFactory.getLogger(AuroraMessageUtils.class);
    //用户端
    public static final String USER_CLIENT = "APP_USER";
    //用户前缀（极光消息）
    public static final String USER_PREFIX = "sy_";
    //商户端
    public static final String BUSINESS_CLIENT = "APP_BUSINESS";
    protected static final String ANDROID = "android";
    protected static final String IOS = "ios";
    protected static final Map<String, Platform> clientMap = new HashMap<>();

    static {
        clientMap.put(ANDROID, Platform.android());
        clientMap.put(IOS, Platform.ios());
        clientMap.put("all", Platform.android_ios());
    }

    public static JMessageClient getJMessageClient(Integer application) {
        JMessageClient jMessageClient = null;
        if (application == Constants.GENERAL_USER_ROLE_ID) {
            jMessageClient = new JMessageClient(AppConfig.getProperty(AuroraConfig.USER_APP_KEY), AppConfig.getProperty(AuroraConfig.USER_MASTER_SECRET));
        } else if (application == Constants.BUSINESS_ROLE_ID || application == Constants.ASSISTANT_ROLE_ID) {
            jMessageClient = new JMessageClient(AppConfig.getProperty(AuroraConfig.BUSINESS_APP_KEY), AppConfig.getProperty(AuroraConfig.BUSINESS_MASTER_SECRET));
        }
        return jMessageClient;
    }


    /**
     * @Description 注册用户端用户至极光
     * @Param BmsUser
     * @Author: cfx
     * @Date: 2019/10/5
     */
    public static void registerGeneralUsers(BmsUser bmsUser) {
        JMessageClient client = getJMessageClient(Constants.GENERAL_USER_ROLE_ID);
        try {
            List<RegisterInfo> users = new ArrayList<>();
            String nickName = BmsUserService.getLoginName(bmsUser);
            String userName = USER_PREFIX + bmsUser.getId().toString();
            Map<String, String> extra = new HashMap<>();
            extra.put("roleId",String.valueOf(Constants.GENERAL_USER_ROLE_ID));
            extra.put("icon", bmsUser.getHeadImg());
            //上传头像
            //uploadUserHeadImg();
            RegisterInfo user = RegisterInfo.newBuilder()
                    .setUsername(userName)
                    .setPassword(Constants.DEFAULT_PASSWORD)
                    .setNickname(nickName)
                    .addExtras(extra)
                    .build();
            users.add(user);
            RegisterInfo[] regUsers = new RegisterInfo[users.size()];
            String res = client.registerUsers(users.toArray(regUsers));
            LOG.info(res);
        } catch (APIConnectionException e) {
            LOG.error("Connection error. Should retry later. ", e);
        } catch (APIRequestException e) {
            if(e.getErrorCode() != ResultCode.JG_USER_EXIST) {
                LOG.error("Error response from JPush server. Should review and fix it. ", e);
                LOG.info("HTTP Status: " + e.getStatus());
                LOG.info("Error Message: " + e.getMessage());
            }
        }catch (Exception e){
            LOG.info(e.getMessage());
        }
    }

    /**
     * 认证成为商家之后需要添加极光推送
     **/
    public static void registerBusinessUsers(List<BmsUserChat> bmsUserChats, BmsBusiness bmsBusiness) {
        JMessageClient client = getJMessageClient(Constants.BUSINESS_ROLE_ID);
        if (bmsUserChats != null && bmsUserChats.size() > 0) {
            for (BmsUserChat bmsUserChat : bmsUserChats) {
                try {
                    List<RegisterInfo> users = new ArrayList<>();
                    String userName = USER_PREFIX + bmsUserChat.getUserId().toString();
                    String nickName = bmsUserChat.getNameInGroupChat();
                    if(nickName.length() > 30){
                        nickName = nickName.substring(0,30);
                    }
                    Map<String, String> extra = new HashMap<>();
                    extra.put("roleId", bmsUserChat.getRoleId().toString());
                    extra.put("icon", bmsBusiness.getLogoUrl());
                    extra.put("businessId",bmsBusiness.getId().toString());
                    //上传头像
                    //uploadUserHeadImg();
                    RegisterInfo user = RegisterInfo.newBuilder()
                            .setUsername(userName)
                            .setPassword(Constants.DEFAULT_PASSWORD)
                            .setNickname(nickName)
                            .addExtras(extra)
                            .build();
                    users.add(user);
                    RegisterInfo[] regUsers = new RegisterInfo[users.size()];
                    String res = client.registerUsers(users.toArray(regUsers));
                    LOG.info(res);
                } catch (APIConnectionException e) {
                    LOG.error("Connection error. Should retry later. ", e);
                } catch (APIRequestException e) {
                    if(e.getErrorCode() != ResultCode.JG_USER_EXIST) {
                        LOG.error("Error response from JPush server. Should review and fix it. ", e);
                        LOG.info("HTTP Status: " + e.getStatus());
                        LOG.info("Error Message: " + e.getMessage());
                    }
                }catch (Exception e){
                    LOG.info(e.getMessage());
                }
            }
        }
    }


    /**
     * 认证成为商家之后需要添加极光推送
     **/
    public static void registerAssistantUsers(List<String> bmsUserChats) {
        JMessageClient client = new JMessageClient(AppConfig.getProperty(AuroraConfig.BUSINESS_APP_KEY), AppConfig.getProperty(AuroraConfig.BUSINESS_MASTER_SECRET));

        try {
            if (bmsUserChats != null && bmsUserChats.size() > 0) {
                for (String nameInGroup : bmsUserChats) {
                    List<RegisterInfo> users = new ArrayList<>();
                    String nickName = nameInGroup;
                    //上传头像
                    //uploadUserHeadImg();
                    RegisterInfo user = RegisterInfo.newBuilder()
                            .setUsername(nickName)
                            .setPassword(Constants.DEFAULT_PASSWORD)
                            .setNickname(nickName)
                            .build();
                    users.add(user);
                    RegisterInfo[] regUsers = new RegisterInfo[users.size()];
                    String res = client.registerUsers(users.toArray(regUsers));
                    LOG.info(res);
                }
            }
        } catch (APIConnectionException e) {
            LOG.error("Connection error. Should retry later. ", e);
        } catch (APIRequestException e) {
            LOG.error("Error response from JPush server. Should review and fix it. ", e);
            LOG.info("HTTP Status: " + e.getStatus());
            LOG.info("Error Message: " + e.getMessage());
        }
    }

    public static void createGroup(BmsDxGroupChat bmsDxGroupChat, String userManager, List<String> memers) {
        //加入模拟用户
        memers.add(AuroraMessageUtils.USER_PREFIX + "X001");
        JMessageClient client = getJMessageClient(Constants.BUSINESS_ROLE_ID);
        try {
            CreateGroupResult res = client.createGroup(userManager, bmsDxGroupChat.getGroupName(), bmsDxGroupChat.getGroupImg(), "", 1, memers.toArray(new String[memers.size()]));
            LOG.info(res.getName());
            bmsDxGroupChat.setGid(res.getGid().toString());
        } catch (APIConnectionException e) {
            LOG.error("Connection error. Should retry later. ", e);
        } catch (APIRequestException e) {
            LOG.error("Error response from JPush server. Should review and fix it. ", e);
            LOG.info("HTTP Status: " + e.getStatus());
            LOG.info("Error Message: " + e.getMessage());
        }
    }

    /**
     * Send group text message by admin
     */
    public static boolean sendGroupMessageByAdmin(String gid,String userName,String text,Map<String,String> extras) {
        JMessageClient client = getJMessageClient(Constants.BUSINESS_ROLE_ID);
        try {
            MessageBody body = MessageBody.newBuilder()
                    .setText(text)
                    .addExtras(extras).build();
            MessagePayload messagePayload =
                    MessagePayload.newBuilder()
                            .setVersion(1)
                            .setTargetType("group")
                            .setFromType("user")
                            .setMessageType(MessageType.TEXT)
                            .setTargetId(gid)
                            //.setTargetAppKey(AuroraConfig.USER_APP_KEY_1)
                            .setFromId(userName)
                            .setMessageBody(body).build();
            SendMessageResult result = client.sendMessage(messagePayload);
            LOG.info(result.toString());
            LOG.info(String.valueOf(result.getMsg_id()));
            return true;
        } catch (APIConnectionException e) {
            LOG.error("Connection error. Should retry later. ", e);
        } catch (APIRequestException e) {
            LOG.error("Error response from JPush server. Should review and fix it. ", e);
            LOG.info("HTTP Status: " + e.getStatus());
            LOG.info("Error Message: " + e.getMessage());
        }
        return false;
    }


    private static void uploadUserHeadImg(String appkey, String masterSecret) {
        ResourceClient client = new ResourceClient(appkey, masterSecret);
        try {
            UploadResult result = client.uploadFile("G:\\MyDownloads\\discourse-icon.pngj", "image");
            String mediaId = result.getMediaId();
        } catch (APIConnectionException e) {
            LOG.error("Connection error. Should retry later. ", e);
        } catch (APIRequestException e) {
            LOG.error("Error response from JPush server. Should review and fix it. ", e);
            LOG.info("HTTP Status: " + e.getStatus());
            LOG.info("Error Message: " + e.getMessage());
        }
    }


    public static void testRegisterUsers() {
        JMessageClient client = new JMessageClient(AuroraConfig.USER_APP_KEY, AuroraConfig.USER_MASTER_SECRET);
        String authCode = ServiceHelper.getBasicAuthorization(AuroraConfig.USER_MASTER_SECRET, AuroraConfig.USER_APP_KEY);
//        ApacheHttpClient httpClient = new ApacheHttpClient(authCode, null, ClientConfig.getInstance());
        // 用 ApacheHttpClient 代替默认的 NativeHttpClient
//        client.setHttpClient(httpClient);
        try {

            List<RegisterInfo> users = new ArrayList<>();

            RegisterInfo user = RegisterInfo.newBuilder()
                    .setUsername("test_user1")
                    .setPassword("test_pass1")
                    .build();

            RegisterInfo user1 = RegisterInfo.newBuilder()
                    .setUsername("test_user2")
                    .setPassword("test_pass2")
                    .addExtra("test", "ttt")
                    .build();

            users.add(user);
            users.add(user1);

            RegisterInfo[] regUsers = new RegisterInfo[users.size()];

            String res = client.registerUsers(users.toArray(regUsers));
            LOG.info(res);
        } catch (APIConnectionException e) {
            LOG.error("Connection error. Should retry later. ", e);
        } catch (APIRequestException e) {
            LOG.error("Error response from JPush server. Should review and fix it. ", e);
            LOG.info("HTTP Status: " + e.getStatus());
            LOG.info("Error Message: " + e.getMessage());
        }


    }



    /*public static void testSendPush_fromJSON() {
        ClientConfig clientConfig = ClientConfig.getInstance();
        JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, clientConfig);
        Gson gson = new GsonBuilder()
                .registerTypeAdapter(PlatformNotification.class, new InterfaceAdapter<>())
                .create();
        // Since the type of DeviceType is enum, thus the value should be uppercase, same with the AudienceType.
        String payloadString = "{\"platform\":{\"all\":false,\"deviceTypes\":[\"IOS\"]},\"audience\":{\"all\":true,\"targets\":[{\"audienceType\":\"TAG_AND\",\"values\":[\"tag1\",\"tag_all\"]}]},\"notification\":{\"notifications\":[{\"soundDisabled\":false,\"badgeDisabled\":false,\"sound\":\"happy\",\"badge\":\"5\",\"contentAvailable\":false,\"alert\":\"Test from API Example - alert\",\"extras\":{\"from\":\"JPush\"},\"type\":\"cn.jpush.api.push.model.notification.IosNotification\"}]},\"message\":{\"msgContent\":\"Test from API Example - msgContent\"},\"options\":{\"sendno\":1429488213,\"overrideMsgId\":0,\"timeToLive\":-1,\"apnsProduction\":true,\"bigPushDuration\":0}}";
        PushPayload payload = gson.fromJson(payloadString, PushPayload.class);
        try {
            PushResult result = jpushClient.sendPush(payloadString);
            LOG.info("Got result - " + result);

        } catch (APIConnectionException e) {
            LOG.error("Connection error. Should retry later. ", e);
            // LOG.error("Sendno: " + payload.getSendno());

        } catch (APIRequestException e) {
            LOG.error("Error response from JPush server. Should review and fix it. ", e);
            LOG.info("HTTP Status: " + e.getStatus());
            LOG.info("Error Code: " + e.getErrorCode());
            LOG.info("Error Message: " + e.getErrorMessage());
            LOG.info("Msg ID: " + e.getMsgId());
            //LOG.error("Sendno: " + payload.getSendno());
        }
    }*/

    public static PushPayload buildPushMessageToAlias(Platform platform, String[] audAlias, Message message, String alert) {
        return PushPayload.newBuilder()
                .setPlatform(platform)
                .setAudience(Audience.alias(audAlias))
                .setMessage(message)
                .setNotification(Notification.alert(alert))
                .build();
    }

    public static PushPayload buildPushMessageToAlias(Platform platform, String[] audAlias, Map<String, String> message, String alert) {
        return PushPayload.newBuilder()
                .setPlatform(platform)
                .setAudience(Audience.alias(audAlias))
                .setNotification(Notification.newBuilder().
                        addPlatformNotification(IosNotification.newBuilder().setAlert(alert).addExtras(message).build())
                        .addPlatformNotification(AndroidNotification.newBuilder().setAlert(alert).addExtras(message).build())
                        .build())
                .build();
    }

    public static PushPayload buildPushMessageToTags(Platform platform, String[] audTags, Message message) {
        return PushPayload.newBuilder()
                .setPlatform(platform)
                .setAudience(Audience.tag(audTags))
                .setMessage(message)
                .build();
    }

    public static void main(String[] args) {
        String a = "{\\\"code\\\":\\\"10000\\\",\\\"data\\\":{\\\"bmsUserId\\\":693,\\\"bmsVideoId\\\":415,\\\"childType\\\":1,\\\"fromOrigin\\\":1,\\\"id\\\":1569,\\\"isNoRead\\\":0,\\\"newTime\\\":1565661327000,\\\"opUserId\\\":788,\\\"parentType\\\":1,\\\"updateTime\\\":1565662532110,\\\"userLikeNum\\\":41,\\\"userList\\\":[{\\\"loginName\\\":\\\"\\U4f5b\\U946b\\U6d4b\\U8bd5\\U53f7\\\",\\\"userid\\\":788},{\\\"loginName\\\":\\\"\\U5e97\\U8001\\U677f\\\",\\\"userid\\\":624},{\\\"loginName\\\":\\\"yugt\\\",\\\"userid\\\":626}],\\\"videoImg\\\":\\\"http://1254456672.vod2.myqcloud.com/ea06baecvodcq1254456672/e3b6694e5285890790751437513/5285890790751437514.jpg\\\",\\\"videoName\\\":\\\"\\U4e45\\U4e45\\U867e\\U4e00\\U9505\\\"}}";
        Map<String, Object> objectMap = (Map<String, Object>) JSON.parse(a);
        System.out.println(objectMap);
    }


    public static boolean genUserJoinGroup(String gid,BmsUser bmsUser) {
        JMessageClient client = getJMessageClient(Constants.BUSINESS_ROLE_ID);
        String[] addList = new String[1];
        addList[0] = AuroraMessageUtils.USER_PREFIX + bmsUser.getId();
        try {
            CrossGroup crossGroup = new CrossGroup.Builder()
                    .setAppKey(AppConfig.getProperty(AuroraConfig.USER_APP_KEY))
                    .setAddUsers(addList)
                    .setRemoveUsers(null).build();
            CrossGroup[] crossGroups = new CrossGroup[]{crossGroup};
            client.addOrRemoveCrossGroupMember(Long.parseLong(gid),crossGroups);
            return true;
        } catch (APIConnectionException e) {
            log.error(e.getMessage(),e);
        } catch (APIRequestException e) {
            if(e.getErrorCode() == ResultCode.JG_USER_IS_JOIN){
                return true;
            }
            log.error(e.getMessage(),e);
        }
        return false;
    }

    public static boolean businessUserJoinGroup(String gid,BmsUserChat bmsUserChat) {
        JMessageClient client = getJMessageClient(Constants.BUSINESS_ROLE_ID);
        String[] addList = new String[1];
        addList[0] = AuroraMessageUtils.USER_PREFIX + bmsUserChat.getUserId();
        try {
            client.addOrRemoveMembers(Long.parseLong(gid),addList,null);
            return true;
        } catch (APIConnectionException e) {
            log.error(e.getMessage(),e);
        } catch (APIRequestException e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }

    public static void addVirtualUser(String gid){
        JMessageClient client = getJMessageClient(Constants.BUSINESS_ROLE_ID);
        String[] addList = new String[1];
        addList[0] = AuroraMessageUtils.USER_PREFIX + "X001";
        try {
            client.addOrRemoveMembers(Long.parseLong(gid), addList,null);
        } catch (APIConnectionException e) {
            log.error(e.getMessage(),e);
        } catch (APIRequestException e) {
            log.error(e.getMessage(),e);
        }
    }

    public static void updateGroupData(BmsDxGroupChat bmsDxGroupChat) {
        JMessageClient client = getJMessageClient(Constants.BUSINESS_ROLE_ID);
        try {
            client.updateGroupInfo(Long.parseLong(bmsDxGroupChat.getGid()), bmsDxGroupChat.getGroupName(), bmsDxGroupChat.getGroupImg(), "");
        } catch (APIConnectionException e) {
            log.error(e.getMessage(),e);
        } catch (APIRequestException e) {
            log.error(e.getMessage(),e);
        }
    }

    public static boolean genUserBackGroup(String gid,BmsUserChat bmsUserChat) {
        JMessageClient client = getJMessageClient(Constants.BUSINESS_ROLE_ID);
        String[] removeList = new String[1];
        removeList[0] = AuroraMessageUtils.USER_PREFIX + bmsUserChat.getUserId();
        try {
            CrossGroup crossGroup = new CrossGroup.Builder()
                    .setAppKey(AppConfig.getProperty(AuroraConfig.USER_APP_KEY))
                    .setAddUsers(null)
                    .setRemoveUsers(removeList).build();
            CrossGroup[] crossGroups = new CrossGroup[]{crossGroup};
            client.addOrRemoveCrossGroupMember(Long.parseLong(gid),crossGroups);
            return true;
        } catch (APIConnectionException e) {
            log.error(e.getMessage(),e);
        } catch (APIRequestException e) {
            if(e.getErrorCode() == ResultCode.JG_USER_IS_NO_JOIN){
                return true;
            }
            log.error(e.getMessage(),e);
        }
        return false;

    }

    public static void buinessUserBackGroup(String gid,BmsUserChat bmsUserChat) {
        JMessageClient client = getJMessageClient(Constants.BUSINESS_ROLE_ID);
        String[] removeList = new String[1];
        removeList[0] = AuroraMessageUtils.USER_PREFIX + bmsUserChat.getUserId();
        try {
            client.addOrRemoveMembers(Long.parseLong(gid),null,removeList);
        } catch (APIConnectionException e) {
            log.error(e.getMessage(),e);
        } catch (APIRequestException e) {
            log.error(e.getMessage(),e);
        }
    }

    public static void updateGeneralUsers(BmsUser bmsUser,Integer roleId){
        try {
            JMessageClient jMessageClient = getJMessageClient(roleId);
            Map<String,String> extraMap = new HashMap<>();
            extraMap.put("roleId",String.valueOf(roleId));
            extraMap.put("icon", bmsUser.getHeadImg());
            UserPayload userPayload = UserPayload.newBuilder()
                    .setNickname(bmsUser.getLoginName())
                    .addExtras(extraMap)
                    .build();
            jMessageClient.updateUserInfo(AuroraMessageUtils.USER_PREFIX + bmsUser.getId(),userPayload);
        } catch (APIConnectionException e) {
            log.error(e.getMessage(),e);
        } catch (APIRequestException e) {
            log.error(e.getMessage(),e);
        }
    }

    public static void updateBusinessUsers(BmsBusiness bmsBusiness,Integer businessUserId,Integer roleId){
        try {
            JMessageClient jMessageClient = getJMessageClient(roleId);
            Map<String,String> extraMap = new HashMap<>();
            extraMap.put("roleId",String.valueOf(roleId));
            extraMap.put("icon", bmsBusiness.getLogoUrl());
            UserPayload userPayload = UserPayload.newBuilder()
                    .setNickname(bmsBusiness.getVendorName())
                    .addExtras(extraMap)
                    .build();
            jMessageClient.updateUserInfo(AuroraMessageUtils.USER_PREFIX + businessUserId,userPayload);
        } catch (APIConnectionException e) {
            log.error(e.getMessage(),e);
        } catch (APIRequestException e) {
            log.error(e.getMessage(),e);
        }
    }

    public static void deleteUsers(Integer businessUserId,Integer roleId){
        try {
            JMessageClient jMessageClient = getJMessageClient(roleId);
            jMessageClient.deleteUser(AuroraMessageUtils.USER_PREFIX + businessUserId);
        } catch (APIConnectionException e) {
            log.error(e.getMessage(),e);
        } catch (APIRequestException e) {
            log.error(e.getMessage(),e);
        }
    }

    public static boolean updateUsersBannerSay(BmsUser bmsUser,Integer roleId,Map<Integer,String> gidMap,List<BmsUserChat> bmsUserChats){
        try {
            Map<String,String> extraMap = new HashMap<>();
            extraMap.put("roleId",String.valueOf(roleId));
            extraMap.put("icon", bmsUser.getHeadImg());
            if(bmsUserChats != null && bmsUserChats.size() > 0){
                for(BmsUserChat bmsUserChat : bmsUserChats){
                    if(gidMap.containsKey(bmsUserChat.getChatId())){
                        extraMap.put(gidMap.get(bmsUserChat.getChatId()),String.valueOf(bmsUserChat.getCanSayTime().getTime()));
                    }
                }
            }
            JMessageClient jMessageClient = getJMessageClient(roleId);
            UserPayload userPayload = UserPayload.newBuilder()
                    .addExtras(extraMap)
                    .build();
            jMessageClient.updateUserInfo(AuroraMessageUtils.USER_PREFIX + bmsUser.getId(),userPayload);
            return true;
        } catch (APIConnectionException e) {
            log.error(e.getMessage(),e);
        } catch (APIRequestException e) {
            log.error(e.getMessage(),e);
        }
        return false;
    }


    public static void bannerUser(String bannerUser,String bannerUserRole,String gid,String status){


        //String url = String.format("https://api.im.jpush.cn/groups/messages/{%s}/silence?status={%s}",gid,"true");
        //Map<String,Object> formData = new HashMap<>();
        //RestTemplateUtils
        /**
         * Get users' state
         *
         * @param users username of users
         * @return {@link UserStateListResult}
         * @throws APIConnectionException connect exception
         * @throws APIRequestException    request exception
         */
       /* public UserStateListResult[] getUsersState(String... users) throws APIConnectionException, APIRequestException {
            JsonArray jsonArray = new JsonArray();
            for (String username : users) {
                StringUtils.checkUsername(username);
                jsonArray.add(new JsonPrimitive(username));
            }
            ResponseWrapper response = _httpClient.sendPost(_baseUrl + userPath + "/userstat", jsonArray.toString());
            return _gson.fromJson(response.responseContent, UserStateListResult[].class);
        }*/

    }

    public static void transferGroupAdmin(String gid,String userName) {
        JMessageClient client = getJMessageClient(Constants.BUSINESS_ROLE_ID);
        try {
            client.changeGroupAdmin(Long.parseLong(gid), AppConfig.getProperty(AuroraConfig.BUSINESS_APP_KEY),userName);
        } catch (APIConnectionException e) {
            log.error(e.getMessage(),e);
        } catch (APIRequestException e) {
            log.error(e.getMessage(),e);
        }
    }
}
